﻿using System;

namespace Jacobi.ComponentModel.Decomposition
{
    /// <summary>
    /// Allows a connected filter to read from a Pipe.
    /// </summary>
    /// <typeparam name="T">The data type of the Pipe.</typeparam>
    public interface IConsumerPort<T>
    {
        /// <summary>
        /// Reads one value from the pipe.
        /// </summary>
        /// <returns>Never returns null or default.</returns>
        /// <remarks>The calling Thread is suspended until data is available.</remarks>
        T Read();
    }

    /// <summary>
    /// Allows a connected filter to write to a pipe.
    /// </summary>
    /// <typeparam name="T">The data type of the pipe.</typeparam>
    public interface IProducerPort<T>
    {
        /// <summary>
        /// Writes one value to a pipe.
        /// </summary>
        /// <param name="data">The data item to write to a pipe.</param>
        void Write(T data);
    }

    /// <summary>
    /// A pipe with its consumer and producer ports.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface IPipe<T>
    {
        /// <summary>
        /// Gets the consumer port for the pipe.
        /// </summary>
        IConsumerPort<T> Consumer { get; }

        /// <summary>
        /// Gets the producer port for the pipe.
        /// </summary>
        IProducerPort<T> Producer { get; }
    }
}
